package com.lovo.service.impl;

import com.lovo.bean.User;
import com.lovo.dao.UserMapper;
import com.lovo.service.IUserService;
import com.lovo.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImpl implements IUserService {
    @Override
    public boolean insertUser(User user) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        int i = mapper.insert(user);
        SqlSessionUtil.commit();
        return i>0?true:false;
    }

    @Override
    public User userLogin(User u) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.selectLogin(u);
        SqlSessionUtil.commit();
        return user;
    }

    @Override
    public User getUserById(int id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.selectByPrimaryKey(id);
        SqlSessionUtil.commit();
        return user;
    }
}
